//
//  DDCollectionVC.m
//  dingdang
//
//  Created by 阮 沧晖 on 15/7/18.
//  Copyright (c) 2015年 阮 沧晖. All rights reserved.
//

#import "DDCollectionVC.h"
#import "DDCollectionContentVC.h"
@interface DDCollectionVC () <ViewPagerDataSource, ViewPagerDelegate>

@end

@implementation DDCollectionVC

- (void)viewDidLoad {
    
   

    
    // Keeps tab bar below navigation bar on iOS 7.0+
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    self.navigationController.navigationBar.hidden = NO;
    self.title = @"我的收藏";
    UIColor * color = [UIColor whiteColor];
    NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:UITextAttributeTextColor];
    self.navigationController.navigationBar.titleTextAttributes = dict;
    //self.navigationController.navigationBar.hidden = NO;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"top_Background"] forBarMetrics:UIBarMetricsDefault];
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [back setFrame:CGRectMake(5,7, 22, 30)];
    [back setImage:[UIImage imageNamed:@"top_返回"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(popVC) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = barButton;
    
    [self performSelector:@selector(navPop) withObject:nil afterDelay:1.0];
    
    sleep(0.5);
    self.dataSource = self;
    self.delegate = self;
    [super viewDidLoad];
    
    
   // self.tabWidth = self.view.frame.size.width/2;
}
-(void)navPop
{
    
}
-(void)viewWillAppear:(BOOL)animated
{
    
    [super viewWillAppear:animated];
    
}
-(void)popVC
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - ViewPagerDataSource
- (NSUInteger)numberOfTabsForViewPager:(ViewPagerController *)viewPager {
    return 2;
}
- (UIView *)viewPager:(ViewPagerController *)viewPager viewForTabAtIndex:(NSUInteger)index {
    
    UILabel *label = [UILabel new];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont systemFontOfSize:20.0];
    NSString *tabName = index == 0 ? @"悬赏题" : @"大家帮";
    label.text = tabName;
    
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor colorWithRed:42.0/255.0 green:172.0/255.0 blue:226.0/255.0 alpha:0.75];
    [label sizeToFit];
    
    return label;
}

- (UIViewController *)viewPager:(ViewPagerController *)viewPager contentViewControllerForTabAtIndex:(NSUInteger)index {
    
    DDCollectionContentVC *cvc = [[DDCollectionContentVC alloc] initWithNibName:@"DDCollectionContentVC" bundle:nil];
    cvc.typeIndex = index;
    //cvc.labelString = [NSString stringWithFormat:@"Content View #%i", index];
    
    return cvc;
}

#pragma mark - ViewPagerDelegate
- (CGFloat)viewPager:(ViewPagerController *)viewPager valueForOption:(ViewPagerOption)option withDefault:(CGFloat)value {
    
    switch (option) {
        case ViewPagerOptionStartFromSecondTab:
            return 0.0;
            break;
        case ViewPagerOptionCenterCurrentTab:
            return 0.0;
            break;
        case ViewPagerOptionTabLocation:
            return 1.0;
            break;
        case ViewPagerOptionTabWidth:
            return  [[UIApplication sharedApplication].delegate window].frame.size.width/2;
            break;
        case ViewPagerOptionTabOffset:
            return 0;
            break;
        default:
            break;
    }
    
    return value;
}
- (UIColor *)viewPager:(ViewPagerController *)viewPager colorForComponent:(ViewPagerComponent)component withDefault:(UIColor *)color {
    
    switch (component) {
        case ViewPagerIndicator:
            return [[UIColor colorWithRed:42.0/255.0 green:172.0/255.0 blue:226.0/255.0 alpha:0.75] colorWithAlphaComponent:0.64];
            break;
        default:
            break;
    }
    
    return color;
}
@end
